package com.feng.leetcode;

/**
 * @author feng
 * @decrition
 * @date 2022/11/30:37
 */
public class L1668 {
    public static void main(String[] args) {
        String sequence = "aaabaaaabaaabaaaabaaaabaaaabaaaaba";
        String word = "aaaba";

        int i = maxRepeating(sequence, word);
        System.out.println(i);
    }
    public static int maxRepeating(String sequence, String word) {
        if (!sequence.contains(word)) {
            return 0;
        }
        int i = sequence.indexOf(word);
        int len = word.length();
        int count = 1;
        int result = 0;
        String substring = sequence.substring(i + len);
        String temp = sequence.substring(i + 1);
        while (substring.contains(word)){
            if (substring.startsWith(word)) {
                count++;
                substring = substring.substring(len);
            } else {
                result = Math.max(result, count);
                substring = temp;
                i = substring.indexOf(word);
                temp = temp.substring(i + 1);
                substring = substring.substring(i + len);
                count = 1;
            }
        }
        result = Math.max(result, count);
        return result;
    }
}
